/* 
 * File:   micro_main.c
 * Author: Ken
 *
 * Created on 03 January 2014, 21:41
 */

#include "board.h"

/*
 * 
 */

#define MICRO_IN    RA0
#define LED1        RB1
#define LED2        RB2
#define LED3        RB3
#define LED4        RB4
#define LED5        RB5

#define OUT1        RC4
#define OUT2        RC5
#define OUT3        RC6
#define OUT4        RC7

__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF);
__CONFIG(BOR4V_BOR40V & WRT_OFF);

void port_init();

int main(int argc, char** argv)
{
    uint8_t count = 0;
    port_init();
    while(1)
    {
        if(MICRO_IN)
        {
            count++;
            __delay_ms(500);
        }

        switch(count)
        {
            case 1:
                LED1 = 1;
                __delay_ms(800);
                LED1 = 0;
                break;
            case 2:
                LED2 = 1;
                __delay_ms(800);
                LED2 = 0;
                break;

            case 3:
                LED3 = 1;
                __delay_ms(800);
                LED3 = 0;
                break;
            case 4:
                LED4 = 1;
                __delay_ms(800);
                LED4 = 0;
                break;

            case 5:
                count = 0;
                LED5 = 1;
                __delay_ms(800);
                LED5 = 0;
                break;
        }
    }
    return 0;
}

void port_init()
{
    ANSEL = 0x00;
    ANSELH = 0x00;
    ADON = 0;

    TRISB = 0x00;
    TRISC = 0x00;
    TRISA0 = 1;
    PORTB = 0;
    PORTC = 0;
}